import { defineStore } from 'pinia'
import type { PartialConsult, ConsultIllness } from '@/types/consult'
import { ConsultType } from '@/enums'
import { ref } from 'vue'
export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    const consult = ref<PartialConsult>({})
    // 设置问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)
    // 设置快速问诊类型 三甲|普通
    const setIllnessType = (type: 0 | 1) => (consult.value.illnessType = type)
    // 设置科室
    const setDepId = (depId: string) => (consult.value.depId = depId)

    //设置病情
    const setIllness = (data: ConsultIllness) => {
      consult.value.consultFlag = data.consultFlag
      consult.value.illnessDesc = data.illnessDesc
      consult.value.illnessTime = data.illnessTime
      consult.value.pictures = data.pictures
    }

    // 记录患者id
    const setPatinetId = (id: string) => {
      consult.value.patientId = id
    }

    // 设置优惠券
    const setCoupon = (id: string) => {
      consult.value.couponId = id
    }

    /**
     * 清空存储数据
     */
    const clear = () => {
      consult.value = {}
    }
    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatinetId,
      setCoupon,
      clear
    }
  },
  {
    persist: true
  }
)
